//
//  Account.swift
//  OCDistributor
//
//  Created by Sam Chen on 2019/12/13.
//  Copyright © 2019 Sam Chen. All rights reserved.
//

/// 分销个人账号信息
public struct OCDistributorAccount: Codable {
    public let customerId: Int
    public let avatar: String
    public let email: String
    public let firstname: String
    public let lastname: String
    public let telephone: String

    /// 推广链接：用于生成二维码
    public let referrerUrl: String

    /// 消息总数
    public let messageCount: Int

    private enum CodingKeys: String, CodingKey {
        case customerId
        case avatar
        case email
        case firstname
        case lastname
        case telephone
        case referrerUrl
        case messageCount = "msgCount"
    }
}

public extension OCDistributorAccount {
    /// 全名
    var fullname: String {
        if lastname.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).isEmpty {
            return firstname
        }
        return [firstname, lastname].joined(separator: " ")
    }

    // 全名 + ID: John Doe [88]
    var fullnameWithId: String { "\(fullname) (ID: \(customerId))" }
}

